const defaultListQuery = {
    keyword: null,
    pageNum: 1,
    pageSize: 5,
    publishStatus: null,
    verifyStatus: null,
    productSn: null,
    productCategoryId: null,
    brandId: null
};
let tempList = [];
const vue=new Vue({
    el: '#app',
    data: function () {
        return {
            visible: false,
            isCollapse: false,
            opened: false,
            isActive: false,
            list:
                [{
                id: 1,
                pic: 'https://lf3-cdn-tos.bytescm.com/obj/static/xitu_juejin_web/e08da34488b114bd4c665ba2fa520a31.svg',
                name: '首页',
                category:'猫',
                price: 100,
                store: 100,
            }, {
                id: 2,
                pic: 'https://lf3-cdn-tos.bytescm.com/obj/static/xitu_juejin_web/e08da34488b114bd4c665ba2fa520a31.svg',
                name: '首页',
                category:'猫',
                price: 100,
                store: 100,
            }, {
                id: 3,
                pic: 'https://lf3-cdn-tos.bytescm.com/obj/static/xitu_juejin_web/e08da34488b114bd4c665ba2fa520a31.svg',
                name: '首页',
                category:'猫',
                price: 100,
                store: 100,
            }, {
                id: 4,
                pic: 'https://lf3-cdn-tos.bytescm.com/obj/static/xitu_juejin_web/e08da34488b114bd4c665ba2fa520a31.svg',
                name: '首页',
                category:'猫',
                price: 100,
                store: 100,
            }, {
                id: 5,
                pic: 'https://lf3-cdn-tos.bytescm.com/obj/static/xitu_juejin_web/e08da34488b114bd4c665ba2fa520a31.svg',
                name: '首页',
                category:'猫',
                price: 100,
                store: 100,
            }, {
                id: 6,
                pic: 'https://lf3-cdn-tos.bytescm.com/obj/static/xitu_juejin_web/e08da34488b114bd4c665ba2fa520a31.svg',
                name: '页',
                category:'猫',
                price: 100,
                store: 100,
            }],
            listLoading: false,
            operateType: null,
            listQuery: {
                keyword: null,
                pageNum: 1,
                pageSize: 5,
                publishStatus: null,
                verifyStatus: null,
                productSn: null,
                productCategoryId: null,
                brandId: null
            },
            total: null,
            selectProductCateValue: null,
            multipleSelection: [],
            productCateOptions:
                [{ label: "猫", value: 1, children: null }, { label: "狗", value: 2, children: null }, { label: "鱼", value: 3, children: null }, { label: "鸟", value: 4, children: null }, { label: "爬行类", value: 5, children: null }],
            operates: [
                {
                    label: "商品上架",
                    value: "publishOn"
                },
                {
                    label: "商品下架",
                    value: "publishOff"
                }
            ],
        }
    },
    methods: {
        handleOpen(key, keyPath) {
            console.log(key, keyPath);
        },
        handleClose(key, keyPath) {
            console.log(key, keyPath);
        },
        sidebarHide() {
            $(".sidebar-container").addClass("sidebar-hide");
            alert("sidebarHide");
        },
        sidebarOpen() {
            $(".sidebar-container").removeClass("sidebar-hide");
            alert("sidebarOpen");
        },
        toggleSideBar() {
            alert("togglesidebar");
        },
        sideBar() {
            alert("sidebar");
        },
        toggleClick() {
            this.isActive = !this.isActive;
            this.isCollapse = !this.isCollapse;
        },
        handleCommand(command) {
            window.location.href = "/home";
        },
        logout() {

        },
        error() {
            this.$message.error('此功能暂未开放');
        },
        getList() {
            this.list=JSON.parse(JSON.stringify(tempList));
        },
        handleSearchList() {
            this.listQuery.pageNum = 1;
            this.getList();
        },
        handleResetSearch() {
            this.selectProductCateValue = [];
            this.listQuery = Object.assign({}, defaultListQuery);
        },
        handleAddProduct() {
            window.location.href = "/addProduct";
        },
        handleSelectionChange(val) {
            this.multipleSelection = val;
        },
        handleSizeChange(val) {
            this.listQuery.pageNum = 1;
            this.listQuery.pageSize = val;
            this.getList();
        },
        handleCurrentChange(val) {
            this.listQuery.pageNum = val;
            this.getList();
        },
        handleBatchOperate() {
            if (this.operateType == null) {
                this.$message({
                    message: '请选择操作类型',
                    type: 'warning',
                    duration: 1000
                });
                return;
            }
            if (this.multipleSelection == null || this.multipleSelection.length < 1) {
                this.$message({
                    message: '请选择要操作的商品',
                    type: 'warning',
                    duration: 1000
                });
                return;
            }
            this.$confirm('是否要进行该批量操作?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                let ids = [];
                for (let i = 0; i < this.multipleSelection.length; i++) {
                    ids.push(this.multipleSelection[i].id);
                }
                switch (this.operateType) {
                    case this.operates[0].value:
                        this.updatePublishStatus(1, ids);
                        break;
                    case this.operates[1].value:
                        this.updatePublishStatus(0, ids);
                        break;
                    default:
                        break;
                }
                this.getList();
            });
        },
        updatePublishStatus(publishStatus, ids) {
            let params = new URLSearchParams();
            params.append('ids', ids);
            params.append('publishStatus', publishStatus);
            updatePublishStatus(params).then(response => {
                this.$message({
                    message: '修改成功',
                    type: 'success',
                    duration: 1000
                });
            });
        },
    },
    created() {
        this.getList();
    },
})

function updatePublishStatus(params) {
    return request({
        url: '/#',
        method: 'post',
        params: params
    })
}
function setList(tpList){
    tempList=JSON.parse(JSON.stringify(tpList));
    vue.getList();
  }